package com.stefan.array;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        InputStreamReader input = new InputStreamReader(new FileInputStream("D:\\Stefan\\tech\\tuling7\\algorithms\\src\\main\\resources\\age.txt"),"utf-8");
        BufferedReader reader = new BufferedReader(input);
        int total = 0;
        int[] data = new int[200];
        String src = null;
        long start = System.currentTimeMillis();
        while ((src = reader.readLine()) != null) {
            int age = Integer.parseInt(src);
            data[age]++;
            total++;
        }
        reader.close();
        long end = System.currentTimeMillis();
        System.out.println("读取数据总数: " + total);
        System.out.println("读取数据耗时: " + (end - start) + "ms");
        System.out.println("年龄分布:");
        for (int i = 0; i < data.length; i++) {
            if (data[i] > 0) {
                System.out.println("年龄 " + i + " 岁: " + data[i] + " 人");
            }
        }
    }
}
